home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Programming / Complete Applications / Screen Savers / Moire (Pascal) / MOIRE.PAS next >
Encoding:
Pascal/Delphi Source File  |  1986-10-22  |  14.1 KB  |  706 lines  |  [TEXT/ttxt]

  1. PROGRAM MOIRE;
  2.  
  3. USES MacIntf,MOIREGLOBALS,ZOOM,MOIREINIT;
  4.  
  5. {$T APPL MRGB            }
  6. {$B+                        }
  7. {$L MOIRE.RSRC        }
  8.  
  9. PROCEDURE UpdateEdit (OnOFf : boolean);
  10. VAR
  11.         index : integer;
  12. BEGIN
  13.     FOR index := 1 TO 6 DO
  14.         IF OnOff THEN
  15.             EnableItem(EditMenu, index)
  16.         ELSE
  17.             DisableItem(EditMenu, index);
  18. END;
  19.  
  20. PROCEDURE DrawHeading (theW : WindowPtr);
  21.     VAR
  22.         theStr : str255;
  23. BEGIN
  24.     theStr := 'Click anywhere in the window to set the origin point';
  25.     SetPort(theW);
  26.     TextFont(3);
  27.     TextSize(9);
  28.     WITH theW^.portRect DO
  29.         BEGIN
  30.             MoveTo((right - left - StringWidth(theStr)) DIV 2, topLine - 6);
  31.             DrawString(theStr);
  32.             MoveTo(left, top + topLine - 3);
  33.             LineTo(right, top + topLine - 3);
  34.             MoveTo(left, top + topLine - 1);
  35.             LineTo(right, top + topLine - 1);
  36.         END;
  37. END;
  38.  
  39. PROCEDURE DrawMoire (thePoint : point;
  40.                                 theWindow : WindowPtr);
  41.     VAR
  42.         x1, y1, x2, y2 : integer;
  43.         vRect : rect;
  44.         tempPort : WindowPtr;
  45. BEGIN
  46.     getPort(tempPort);
  47.     setPort(theWindow);
  48.     PenNormal;
  49.     PenMode(patXor);
  50.     CASE CurrentPat OF
  51.         3 : 
  52.             PenPat(black);
  53.         4 : 
  54.             PenPat(dkGray);
  55.         5 : 
  56.             PenPat(gray);
  57.         6 : 
  58.             PenPat(ltGray);
  59.     END;
  60.     x1 := thePoint.h;
  61.     y1 := thePoint.v;
  62.     clipRect(MoireRect);
  63.     IF flashPhase THEN
  64.         InvertRect(MoireRect);
  65.     HideCursor;
  66.     WITH MoireRect DO
  67.         BEGIN
  68.             x2 := right;
  69.             y2 := top;
  70.             WHILE x2 >= left DO
  71.                 BEGIN
  72.                     MoveTo(x1, y1);
  73.                     LineTo(x2, y2);
  74.                     x2 := x2 - step;
  75.                 END;
  76.             WHILE y2 <= bottom DO
  77.                 BEGIN
  78.                     MoveTo(x1, y1);
  79.                     LineTo(x2, y2);
  80.                     y2 := y2 + step;
  81.                 END;
  82.             WHILE x2 <= right DO
  83.                 BEGIN
  84.                     MoveTo(x1, y1);
  85.                     LineTo(x2, y2);
  86.                     x2 := x2 + step;
  87.                 END;
  88.             WHILE y2 >= top DO
  89.                 BEGIN
  90.                     MoveTo(x1, y1);
  91.                     LineTo(x2, y2);
  92.                     y2 := y2 - step;
  93.                 END;
  94.         END;
  95.     ShowCursor;
  96.     flashVal := tickCount;
  97.     PenNormal;
  98.     clipRect(theWindow^.portRect);
  99.     setPort(tempPort);
  100. END;
  101.  
  102. PROCEDURE CheckFlash;
  103.     VAR
  104.         tempPort : WindowPtr;
  105.         flashRect : rect;
  106. BEGIN
  107.     IF (tickCount - flashVal) >= flashRate THEN
  108.         BEGIN
  109.             GetPort(tempPort);
  110.             SetPort(myWindow);
  111.             invertRect(MoireRect);
  112.             flashPhase := NOT flashPhase;
  113.             flashVal := tickCount;
  114.             setPort(tempPort);
  115.         END;
  116. END;
  117.  
  118. PROCEDURE DoAppleMenu (theItem : integer);
  119.     VAR
  120.         ignore : integer;
  121.         accName : Str255;
  122.         accNum : integer;
  123. BEGIN
  124.     IF theItem = 1 THEN
  125.         BEGIN
  126.             ignore := Alert(AboutID, NIL);
  127.         END
  128.     ELSE
  129.         BEGIN
  130.             GetItem(AppleMenu, theItem, accName);
  131.             accNum := OpenDeskAcc(accName);
  132.         END;
  133. END;
  134.  
  135. PROCEDURE DoFileMenu (theItem : integer);
  136. BEGIN
  137.     CASE theItem OF
  138.         1 : 
  139.             BEGIN
  140.                 Finished := TRUE;
  141.             END;
  142.     END;
  143. END;
  144.  
  145. PROCEDURE DoEditMenu (theItem : integer);
  146. BEGIN
  147.     IF NOT SystemEdit(theItem - 1) THEN
  148.         BEGIN
  149.             CASE theItem OF
  150.                 UndoItem : 
  151.                     ;
  152.                 { Undo PROCEDURE }
  153.                 CutItem : 
  154.                     ;
  155.                 { Cut PROCEDURE }
  156.                 CopyItem : 
  157.                     ;
  158.                 { Copy PROCEDURE }
  159.                 PasteItem : 
  160.                     ;
  161.                 { Paste PROCEDURE }
  162.                 ClearItem : 
  163.                     ;
  164.                 { Clear PROCEDURE }
  165.             END;
  166.         END;
  167. END;
  168.  
  169. FUNCTION MyPatDlg (theDialog : DialogPtr;
  170.                                 VAR dEvent : EventRecord;
  171.                                 VAR itemHit : integer) : boolean;
  172.     VAR
  173.         ch : integer;
  174.         thePoint : point;
  175.         ItemIndex : integer;
  176.         dType : integer;
  177.         dHandle : Handle;
  178.         dRect : rect;
  179.  
  180.     PROCEDURE MakeWhite (dItem : integer);
  181.     BEGIN
  182.         GetDItem(theDialog, dItem, dType, dHandle, dRect);
  183.         insetRect(dRect, -4, -4);
  184.         PenSize(2, 2);
  185.         PenPat(white);
  186.         FrameRect(dRect);
  187.     END;
  188.  
  189.     PROCEDURE MakeBlack (dItem : integer);
  190.     BEGIN
  191.         GetDItem(theDialog, dItem, dType, dHandle, dRect);
  192.         insetRect(dRect, -4, -4);
  193.         PenSize(2, 2);
  194.         PenPat(black);
  195.         FrameRect(dRect);
  196.     END;
  197.  
  198. BEGIN
  199.     SetPort(theDialog);
  200.  
  201. (*  check to see if it's time to flash selection  *)
  202.  
  203.     IF (tickCount - timeVal) > dflashRate THEN
  204.         BEGIN
  205.             GetDItem(theDialog, tempPat, dType, dHandle, dRect);
  206.             InsetRect(dRect, -4, -4);
  207.             PenSize(2, 2);
  208.             PenMode(patXor);
  209.             FrameRect(dRect);
  210.             PenNormal;
  211.             timeVal := tickCount;
  212.         END;
  213.  
  214. (* assume that we'll handle these events *)
  215.     MyPatDlg := FALSE;
  216.  
  217. (* find out what kind of event *)
  218.     CASE dEvent.what OF
  219.         MouseDown : 
  220.  
  221. (* check if mouse click was in any of the selectable items *)
  222. (* by calling PtInRect(mouseclick,itemrect)                *)
  223.  
  224.             BEGIN
  225.                 thePoint := dEvent.where;
  226.                 GlobalToLocal(thePoint);
  227.                 FOR ItemIndex := 3 TO 6 DO
  228.                     BEGIN
  229.                         GetDItem(theDialog, ItemIndex, dType, dHandle, dRect);
  230.                         IF PtInRect(thePoint, dRect) THEN
  231.                             BEGIN
  232.                                 IF ItemIndex <> tempPat THEN
  233.  
  234. (* if it was, user made new selection, so...   *)
  235. (* clear out old selection, make new selection *)
  236.  
  237.                                     BEGIN
  238.                                         MakeWhite(tempPat);
  239.                                         tempPat := ItemIndex;
  240.                                         MakeBlack(tempPat);
  241.                                         timeVal := tickCount;
  242.                                     END;
  243.                             END;
  244.                     END;
  245.             END;
  246.  
  247. (* check keydown events for "RETURN" (13)       *)
  248. (* and "ENTER" (03) keys, if so let ModalDialog *)
  249. (* handle them by passing function result of    *)
  250. (* TRUE and an itemHit of 1                     *)
  251.  
  252.         KeyDown : 
  253.             BEGIN
  254.                 ch := BitAnd(dEvent.message, CharCodeMask);
  255.                 CASE ch OF
  256.                     13, 3 : 
  257.                         BEGIN
  258.                             ItemHit := 1;
  259.                             MyPatDlg := TRUE;
  260.                         END;
  261.  
  262. (* if not "RETURN" or "ENTER", let user make    *)
  263. (* selection from keyboard using the arrow keys *)
  264.  
  265.                     28 : 
  266.                         IF (tempPat = 5) OR (tempPat = 6) THEN
  267.                             BEGIN
  268.                                 MakeWhite(tempPat);
  269.                                 tempPat := tempPat - 2;
  270.                                 MakeBlack(tempPat);
  271.                                 timeVal := tickCount;
  272.                             END;
  273.                     29 : 
  274.                         IF (tempPat = 3) OR (tempPat = 4) THEN
  275.                             BEGIN
  276.                                 MakeWhite(tempPat);
  277.                                 tempPat := tempPat + 2;
  278.                                 MakeBlack(tempPat);
  279.                                 timeVal := tickCount;
  280.                             END;
  281.                     30 : 
  282.                         IF (tempPat = 4) OR (tempPat = 6) THEN
  283.                             BEGIN
  284.                                 MakeWhite(tempPat);
  285.                                 tempPat := tempPat - 1;
  286.                                 MakeBlack(tempPat);
  287.                                 timeVal := tickCount;
  288.                             END;
  289.                     31 : 
  290.                         IF (tempPat = 3) OR (tempPat = 5) THEN
  291.                             BEGIN
  292.                                 MakeWhite(tempPat);
  293.                                 tempPat := tempPat + 1;
  294.                                 MakeBlack(tempPat);
  295.                                 timeVal := tickCount;
  296.                             END;
  297.                 END;
  298.             END;
  299.     END;
  300. END;
  301.  
  302. PROCEDURE ourItems (theWindow : WindowPtr;
  303.                                 theItem : integer);
  304.     VAR
  305.         dType : integer;
  306.         dHandle : Handle;
  307.         dRect : rect;
  308. BEGIN
  309.     GetDItem(theWindow, theItem, dType, dHandle, dRect);
  310.     CASE theItem OF
  311.         blackID : 
  312.             FillRect(dRect, black);
  313.         dkGrayID : 
  314.             FillRect(dRect, dkGray);
  315.         grayID : 
  316.             FillRect(dRect, gray);
  317.         ltGrayID : 
  318.             FillRect(dRect, ltGray);
  319.     END;
  320.     IF theItem = tempPat THEN
  321.         BEGIN
  322.             insetRect(dRect, -4, -4);
  323.             PenPat(black);
  324.             PenSize(2, 2);
  325.             FrameRect(dRect);
  326.         END;
  327. END;
  328.  
  329. PROCEDURE DoPatternMenu (theItem : integer);
  330.     VAR
  331.         PatternDlg : DialogPtr;
  332.         whichItem : integer;
  333.         bHit : integer;
  334.         dType : integer;
  335.         dHandle : Handle;
  336.         dRect : rect;
  337.         dText : Str255;
  338.         tStep : longint;
  339. BEGIN
  340.     CASE theItem OF
  341.         PatItem : 
  342.             BEGIN
  343.                 tempPat := CurrentPat;
  344.                 PatternDlg := GetNewDialog(PatternDlgID, NIL, WindowPtr(-1));
  345.                 FOR whichItem := blackID TO ltgrayID DO
  346.                     BEGIN
  347.                         GetDItem(PatternDlg, whichItem, dType, dHandle, dRect);
  348.                         SetDItem(PatternDlg, whichItem, dType, @ourItems, dRect);
  349.                     END;
  350.                 ShowWindow(PatternDlg);
  351.                 timeVal := tickCount;
  352.                 REPEAT
  353.                     ModalDialog(@MyPatDlg, bHit);
  354.                 UNTIL bHit < 3;
  355.                 DisposDialog(PatternDlg);
  356.                 IF bHit = 1 THEN
  357.                     BEGIN
  358.                         IF CurrentPat <> tempPat THEN
  359.                             BEGIN
  360.                                 CurrentPat := tempPat;
  361.                                 SetPort(myWindow);
  362.                                 InvalRect(myWindow^.portRect);
  363.                             END;
  364.                     END;
  365.             END;
  366.         StepItem : 
  367.             BEGIN
  368.                 PatternDlg := GetNewDialog(StepID, NIL, WindowPtr(-1));
  369.                 GetDItem(PatternDlg, 5, dType, dHandle, dRect);
  370.                 NumToString(Step, dText);
  371.                 SetIText(dHandle, dText);
  372.                 SelIText(PatternDlg, 5, 0, 100);
  373.                 ShowWindow(PatternDlg);
  374.                 REPEAT
  375.                     ModalDialog(NIL, bHit);
  376.                 UNTIL bHit < 3;
  377.                 IF bHit = 1 THEN
  378.                     BEGIN
  379.                         GetDItem(PatternDlg, 5, dType, dHandle, dRect);
  380.                         GetIText(dHandle, dText);
  381.                         StringToNum(dText, tStep);
  382.                     END;
  383.                 DisposDialog(PatternDlg);
  384.                 SetPort(myWindow);
  385.                 IF (bHit = 1) AND NOT (tStep = step) THEN
  386.                     IF (LoWord(tStep) > 0) AND (LoWord(tStep) < 65) THEN
  387.                         BEGIN
  388.                             step := LoWord(tStep);
  389.                             InvalRect(myWindow^.portRect);
  390.                         END;
  391.             END;
  392.         InvertItem : 
  393.             BEGIN
  394.                 SetPort(myWindow);
  395.                 InvertRect(MoireRect);
  396.                 flashPhase := NOT flashPhase;
  397.             END;
  398.         FlashItem : 
  399.             BEGIN
  400.                 Flashing := NOT Flashing;
  401.                 IF Flashing THEN
  402.                     BEGIN
  403.                         CheckItem(PatMenu, FlashItem, TRUE);
  404.                         HiliteControl(FlashControl, active);
  405.                     END
  406.                 ELSE
  407.                     BEGIN
  408.                         CheckItem(PatMenu, FlashItem, FALSE);
  409.                         HiliteControl(FlashControl, inactive);
  410.                     END;
  411.             END;
  412.     END;
  413. END;
  414.  
  415. PROCEDURE DoMenuChoice (theChoice : longint);
  416.     VAR
  417.         theMenu, theItem : integer;
  418. BEGIN
  419.     theMenu := HiWord(theChoice);
  420.     theItem := LoWord(theChoice);
  421.     CASE theMenu OF
  422.         AppleID : 
  423.             DoAppleMenu(theItem);
  424.         FileID : 
  425.             DoFileMenu(theItem);
  426.         EditID : 
  427.             DoEditMenu(theItem);
  428.         PatMenuID : 
  429.             DoPatternMenu(theItem);
  430.     END;
  431.     HiliteMenu(0);
  432. END;
  433.  
  434. PROCEDURE DoMenuClick;
  435.     VAR
  436.         menuChoice : longint;
  437. BEGIN
  438.     menuChoice := MenuSelect(theEvent.where);
  439.     DoMenuChoice(menuChoice);
  440. END;
  441.  
  442. PROCEDURE contScroll (theControl : ControlHandle;
  443.                                 thePart : integer);
  444.     VAR
  445.         delta : integer;
  446. BEGIN
  447.     CASE thePart OF
  448.         inUpButton : 
  449.             delta := -1;
  450.         inDownButton : 
  451.             delta := 1;
  452.         inPageUp : 
  453.             delta := -8;
  454.         inPageDown : 
  455.             delta := 8;
  456.     END;
  457.     IF thePart <> 0 THEN
  458.         SetCtlValue(theControl, GetCtlValue(theControl) + delta);
  459. END;
  460.  
  461. PROCEDURE HandleScroll (theControl : ControlHandle;
  462.                                 thePart : integer;
  463.                                 thePoint : point);
  464.     VAR
  465.         dummy : integer;
  466. BEGIN
  467.     IF thePart = inThumb THEN
  468.         BEGIN
  469.             dummy := TrackControl(theControl, thePoint, NIL);
  470.             flashRate := GetCtlValue(theControl);
  471.         END
  472.     ELSE
  473.         BEGIN
  474.             dummy := TrackControl(theControl, thePoint, @contScroll);
  475.             flashRate := GetCtlValue(theControl);
  476.         END
  477. END;
  478.  
  479. PROCEDURE DoContent (theWindow : WindowPtr;
  480.                                 where : point);
  481.     VAR
  482.         theLong : longint;
  483.         longStr : Str255;
  484.         thePoint : point;
  485.         thePart : integer;
  486.         theControl : ControlHandle;
  487. BEGIN
  488.     IF theWindow <> FrontWindow THEN
  489.         SelectWindow(theWindow)
  490.     ELSE
  491.         BEGIN
  492.             thePoint := where;
  493.             GlobalToLocal(thePoint);
  494.             IF PtInRect(thePoint, MoireRect) THEN
  495.                 BEGIN
  496.                     LastPoint := thePoint;
  497.                     InvalRect(theWindow^.portRect)
  498.                 END
  499.             ELSE
  500.                 BEGIN
  501.                     thePart := FindControl(thePoint, theWindow, theControl);
  502.                     IF theControl = FlashControl THEN
  503.                         HandleScroll(theControl, thePart, thePoint);
  504.                 END;
  505.         END;
  506. END;
  507.  
  508. PROCEDURE DoDrag (theWindow : WindowPtr);
  509.     VAR
  510.         Limit : rect;
  511. BEGIN
  512.     SetRect(Limit, -32767, -32767, 32766, 32766);
  513.     DragWindow(theWindow, theEvent.where, Limit);
  514. END;
  515.  
  516. PROCEDURE DoGrow (theWindow : WindowPtr);
  517.     VAR
  518.         sizeRect : rect;
  519.         newSize : longint;
  520.         newWidth, newHeight : integer;
  521. BEGIN
  522.     IF theWindow <> FrontWindow THEN
  523.         SelectWindow(theWindow)
  524.     ELSE
  525.         BEGIN
  526.             SetRect(sizeRect, -32767, -32767, 32766, 32766);
  527.             newSize := GrowWindow(theWindow, theEvent.where, sizeRect);
  528.             IF newSize <> 0 THEN
  529.                 BEGIN
  530.                     EraseRect(theWindow^.portRect);
  531.                     newWidth := LoWord(newSize);
  532.                     newHeight := HiWord(newSize);
  533.                     SizeWindow(theWindow, newWidth, newHeight, TRUE);
  534.                     InvalRect(theWindow^.portRect);
  535.                 END;
  536.         END;
  537. END;
  538.  
  539. PROCEDURE HandleWClose (whichWindow : WindowPtr;
  540.                                 where : point);
  541. BEGIN
  542.     IF whichWindow <> FrontWindow THEN
  543.         SelectWindow(whichWindow)
  544.     ELSE
  545.         BEGIN
  546.             IF TrackGoAway(whichWindow, where) THEN
  547.                 Finished := TRUE;
  548.         END;
  549. END;
  550.  
  551. PROCEDURE HandleMDown;
  552.     VAR
  553.         whichWindow : windowPtr;
  554.         thePart : integer;
  555. BEGIN
  556.     whichWindow := WindowPtr(theEvent.message);
  557.     thePart := FindWindow(theEvent.where, whichWindow);
  558.     CASE thePart OF
  559.         InDesk : 
  560.             sysBeep(1);
  561.         InMenuBar : 
  562.             DoMenuClick;
  563.         InSysWindow : 
  564.             SystemClick(theEvent, whichWindow);
  565.         InContent : 
  566.             DoContent(whichWindow, theEvent.where);
  567.         InDrag : 
  568.             DoDrag(whichWindow);
  569.         InGrow : 
  570.             DoGrow(whichWindow);
  571.         InGoAway : 
  572.             HandleWClose(whichWindow, theEvent.where);
  573.         InZoomOut : 
  574.             BEGIN
  575.                 IF TrackBox(whichWindow, theEvent.where, InZoomOut) THEN
  576.                     BEGIN
  577.                         ZoomWindow(whichWindow, InZoomOut, FALSE);
  578.                         EraseRect(whichWindow^.portRect);
  579.                     END;
  580.             END;
  581.         InZoomIn : 
  582.             BEGIN
  583.                 IF TrackBox(whichWindow, theEvent.where, InZoomIn) THEN
  584.                     BEGIN
  585.                         ZoomWindow(whichWindow, InZoomIn, FALSE);
  586.                         EraseRect(whichWindow^.portRect);
  587.                     END;
  588.             END;
  589.     END;
  590. END;
  591.  
  592. PROCEDURE HandleKDown;
  593.     VAR
  594.         chCode : integer;
  595.         ch : char;
  596.         menuChoice : longint;
  597.         dummyStr : str255;
  598.         eRect : rect;
  599. BEGIN
  600.     WITH theEvent DO
  601.         BEGIN
  602.             chCode := BitAnd(message, CharCodeMask);
  603.             ch := CHR(chCode);
  604.             IF BitAnd(modIFiers, CmdKey) <> 0 THEN
  605.                 BEGIN
  606.                     IF what <> AutoKey THEN
  607.                         BEGIN
  608.                             menuChoice := MenuKey(ch);
  609.                             DoMenuChoice(menuChoice);
  610.                         END;
  611.                 END
  612.             ELSE
  613.                 BEGIN
  614.                 END;
  615.         END;
  616. END;
  617.  
  618. PROCEDURE HandleUpdate;
  619.     VAR
  620.         ActivePort, whichWindow : WindowPtr;
  621. BEGIN
  622.     GetPort(ActivePort);
  623.     whichWindow := WindowPtr(theEvent.message);
  624.     SetPort(whichWindow);
  625.     IF whichWindow = myWindow THEN
  626.         BEGIN
  627.             BeginUpdate(whichWindow);
  628.             EraseRect(whichWindow^.portRect);
  629.             DrawControls(whichWindow);
  630.             DrawHeading(whichWindow);
  631.             DrawMoire(LastPoint, whichWindow);
  632.             EndUpdate(whichWindow);
  633.         END;
  634.     SetPort(ActivePort);
  635. END;
  636.  
  637. PROCEDURE HandleActivate;
  638.     CONST
  639.         changeFlag = $0002;
  640.         active = 0;
  641.         inactive = 255;
  642.     VAR
  643.         whichWindow : WindowPtr;
  644. BEGIN
  645.     WITH theEvent DO
  646.         BEGIN
  647.             whichWindow := WindowPtr(message);
  648.             SetPort(whichWindow);
  649.             IF BitAnd(modIFiers, ActiveFlag) <> 0 THEN
  650.                 BEGIN
  651.                     IF flashing THEN
  652.                         HiliteControl(FlashControl, active)
  653.                     ELSE
  654.                         HiliteControl(FlashControl, inactive);
  655.                     EnableItem(FileMenu, 0);
  656.                     EnableItem(PatMenu, 0);
  657.                     DrawMenuBar;
  658.                     IF BitAnd(modIFiers, changeFlag) <> 0 THEN
  659.                         UpdateEdit(FALSE);
  660.                 END
  661.             ELSE
  662.                 BEGIN
  663.                     HiliteControl(FlashControl, inactive);
  664.                     DisableItem(FileMenu, 0);
  665.                     DisableItem(PatMenu, 0);
  666.                     DrawMenuBar;
  667.                     IF BitAnd(modIFiers, changeFlag) <> 0 THEN
  668.                         UpdateEdit(TRUE);
  669.                 END;
  670.         END;
  671. END;
  672.  
  673. PROCEDURE HandleAnEvent;
  674. BEGIN
  675.     CASE theEvent.what OF
  676.         MouseDown : 
  677.             HandleMDown;
  678.         KeyDown, AutoKey : 
  679.             HandleKDown;
  680.         UpdateEvt : 
  681.             HandleUpdate;
  682.         ActivateEvt : 
  683.             HandleActivate;
  684.     END;
  685. END;
  686.  
  687. PROCEDURE MainLoop;
  688. BEGIN
  689.     SystemTask;
  690.     IF GetNextEvent(EveryEvent, theEvent) THEN
  691.         HandleAnEvent;
  692.     IF Flashing THEN
  693.         CheckFlash;
  694. END;
  695.  
  696. BEGIN (*  main program  *)
  697. Init;
  698. MakeMenus;
  699. MakeWindow;
  700. Finished := FALSE;
  701. REPEAT
  702.     MainLoop;
  703. UNTIL Finished;
  704. LoseWindow(myWindow);
  705. FlushEvents(everyEvent, 0);
  706. END.